<template>

  <div>
    <div>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: $route.path }">{{ $route.meta.title }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!--    <div>-->
    <el-select v-model="value" placeholder="请选择任务名称" size="mini">
      <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
      </el-option>
    </el-select>
    <el-input v-model="search2" placeholder="请输入学校名称" style="width: 12%;margin-left: 10px" size="mini"></el-input>
    <span style="margin-left: 10px;margin-right: 10px">完成状态</span>
    <el-radio v-model="radio1" label="1">已完成</el-radio>
    <el-radio v-model="radio1" label="2">未完成</el-radio>
    <span style="margin-left: 10px;margin-right: 10px">评审状态</span>
    <el-radio v-model="radio2" label="1">是</el-radio>
    <el-radio v-model="radio2" label="2">否</el-radio>
    <span style="margin-left: 10px;margin-right: 10px">任务状态</span>
    <el-radio v-model="radio3" label="1">未开始</el-radio>
    <el-radio v-model="radio3" label="2">进行中</el-radio>
    <el-radio v-model="radio3" label="3">已过期</el-radio>
<!--    <el-input v-model="search" placeholder="请输入要查询的字段的值" style="width: 20%;margin-left: 10px" size="mini"></el-input>-->
    <el-button type="primary" style="margin-top: 10px;margin-left: 10px" @click="ShowSearch()" icon="el-icon-search" size="mini">查询</el-button>
    <!--    </div>-->
    <div style="margin-top: 10px;margin-bottom: 10px">
      <el-button
          size="mini"
          type="primary"
          style="width: 160px"
          class="handle-del mr10"
          @click="ShowAllTA"
      >展示所有数据</el-button>
      <el-button
          size="mini"
          style="width: 160px"
          type="primary"
          class="handle-del mr10"
          @click="Export()"
          icon="el-icon-download"
      >导出</el-button>
    </div>
    <el-table
        size="mini"
        :data=this.tableData
        :row-style="{height:'10px'}"
        :cell-style="{padding:'0px'}"
        border
        :header-cell-style="{background:'lightblue',color:'#262626'}"
        style="width: 991px">
      <el-table-column
          prop="evaluatetaskid"
          label="任务号"
          align="center"
          width="80">
      </el-table-column>
      <el-table-column
          prop="evaluatetaskname"
          label="任务名称"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="schoolname"
          label="学校名称"
          align="center"
          width="280">
      </el-table-column>
<!--      <el-table-column-->
<!--          prop="evaluatetaskname"-->
<!--          label="任务名称"-->
<!--          align="center"-->
<!--          width="280">-->
<!--      </el-table-column>-->
      <el-table-column
          prop="isfinished"
          label="是否完成"
          align="center"
          width="80">
      </el-table-column>
      <el-table-column
          prop="isfinished"
          label="是否评审"
          align="center"
          width="80">
      </el-table-column>
      <el-table-column
          prop="evaluateattitude"
          label="任务状态"
          align="center"
          width="80">
      </el-table-column>
      <el-table-column
          label="操作"
          align="center"
          width="210">
        <template slot-scope="scope">
          <el-button @click="detail(scope.row),dialogFormVisible2 = true" type="text" size="small">查看详情</el-button>
          <el-button @click="Evaluate(scope.row)" type="text" size="small">查看评估</el-button>
          <el-button @click="edit(scope.row),dialogFormVisible = true" type="text" size="small">修改</el-button>
          <el-button @click="del(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-table
        :data=this.tableData1
        border
        hidden
        id="out-table1"
        :header-cell-style="{background:'lightblue',color:'#262626'}"
        style="width: 461px">
      <el-table-column
          prop="evaluatetaskid"
          label="任务号"
          width="80">
      </el-table-column>
      <el-table-column
          prop="schoolname"
          label="学校名称"
          width="280">
      </el-table-column>
    </el-table>
    <el-pagination
        background
        style="margin-top: 10px"
        layout="prev, pager, next"
        page-size="15"
        v-show="isShow"
        :total="total"
        @current-change="page">
    </el-pagination>
    <!--    修改/删除的弹框-->
    <el-dialog :title=this.modeName :visible.sync="dialogFormVisible" :show-close=false width="950px">
      <hr style="margin-top: -30px;margin-bottom: 10px">
      <el-form :model="ruleForm" :rules="rules" :inline="true" ref="ruleForm" label-width="180px" class="demo-ruleForm">
        <el-form-item label="评估任务号" prop="evaluatetaskid">
          <el-input v-model="ruleForm.evaluatetaskid"></el-input>
        </el-form-item>
        <el-form-item label="学校名称" prop="schoolname">
          <el-input v-model="ruleForm.schoolname"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('ruleForm'),allid=''">确定更新</el-button>
<!--        <el-button @click="resetForm('ruleForm')">重置</el-button>-->
        <el-button @click="dialogFormVisible = false,allid=''">取 消</el-button>
        <!--        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>-->
      </div>
    </el-dialog>
    <!--    查看详情的弹框-->
    <el-dialog title="评估任务信息" :visible.sync="dialogFormVisible2" :show-close=false width="1366px">
      <hr style="margin-top: -30px;margin-bottom: 10px">
      <el-table
          size="mini"
          :row-style="{height:'10px'}"
          :cell-style="{padding:'0px'}"
          :data=tableData2
          border
          :header-cell-style="{background:'lightblue',color:'#262626'}"
          style="width: 1366px">
        <el-table-column
            prop="evaluatetaskid"
            label="评估任务号"
            align="center"
            width="95">
        </el-table-column>
        <el-table-column
            prop="evaluatetaskname"
            label="评估任务名称"
            align="center"
            width="150">
        </el-table-column>
        <el-table-column
            prop="evaluateid"
            label="评估号"
            align="center"
            width="80">
        </el-table-column>
        <el-table-column
            prop="evaluatetaskopentime"
            label="评估任务开始时间"
            align="center"
            width="180">
        </el-table-column>
        <el-table-column
            prop="evaluatetaskendtime"
            label="评估任务结束时间"
            align="center"
            width="180">
        </el-table-column>
        <el-table-column
            prop="evaluatetaskcontent"
            label="评估任务内容"
            align="center"
            width="300">
        </el-table-column>
        <el-table-column
            prop="selectedschoolnumber"
            label="已选学校数"
            align="center"
            width="80">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible2 = false">取 消</el-button>
      </div>
    </el-dialog>
    <!--    查看学校填写的信息以及专家的评审结果的弹框-->
    <el-dialog title="已提交的评估任务信息" :visible.sync="dialogFormVisible3" :show-close=false width="1366px">
      <hr style="margin-top: -30px;margin-bottom: 10px">
      <!--      学校提交的信息(包括专家评审信息)-->

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisible3 = false">确定</el-button>
        <el-button @click="dialogFormVisible3 = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  methods:{
    page(currentPage){
      const _this=this
      this.returnPage=currentPage
      axios.get('http://localhost:8081/evaluatetaskarrange/page?current='+currentPage+'&size=15').then(function (res) {
        // console.log(res.data)
        _this.tableData = res.data.evaluatetaskarrangeList;
        _this.total = res.data.total;
      })
    },
    submitForm(formName) {
      const _this=this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.allid){
            axios.put("http://localhost:8081/evaluatetaskarrange/update",this.ruleForm).then(function (res){
              if (res.data.msg==="更新成功"){
                _this.$message({
                  message: '更新成功！',
                  type: 'success'
                  //添加成功后页面跳转
                });
                // _this.$router.push('/EvaluateTaskArrange')
                _this.dialogFormVisible=false
                this.ShowAllTA()
              }
              else{
                _this.$message({
                  message: '评估任务号不存在或者学校不存在！请重新输入',
                  type: 'fail'
                });
              }
            })
          }
          else {
            axios.post("http://localhost:8081/evaluatetaskarrange/save/",this.ruleForm).then(function (res){
              if (res.data.msg==="发布成功"){
                _this.$message({
                  message: '发布成功！',
                  type: 'success'
                  //添加成功后页面跳转
                });
                // _this.$router.push('/EvaluateTaskArrange')
                _this.dialogFormVisible=false
                this.ShowAllTA()
              }
              else{
                _this.$message({
                  message: '该学校不存在或者评估任务号不存在！请重新输入',
                  type: 'fail'
                });
              }
            })
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    ShowAllTA(){
      const _this=this
      axios.get('http://localhost:8081/evaluatetaskarrange/findAll').then(function (res){
        _this.tableData=res.data
      })
    },
    ShowSearch(){
      const _this=this
      // axios.get("http://localhost:8081/evaluatetaskarrange/search/"+this.value+'/'+this.search).then(function (res){
      //   _this.tableData=res.data
      //   _this.search=''
      // })
      this.isShow=false
      let tranR1;
      let tranR2;
      let tranR3;
      if (this.value===''){
        this.value='all'
      }
      if (this.search2===''){
        this.search2='all'
      }
      if(this.radio1==='1'){
          tranR1='是'
      }
      if(this.radio1==='2'){
        tranR1='否'
      }
      if(this.radio2==='1'){
        tranR2='是'
      }
      if(this.radio2==='2'){
        tranR2='否'
      }
      if(this.radio3==='1'){
        tranR3='未开始'
      }
      if(this.radio3==='2'){
        tranR3='进行中'
      }
      if(this.radio3==='3'){
        tranR3='已过期'
      }
      let searchUrl=this.value+'/'+this.search2+'/'+tranR1+'/'+tranR2+'/'+tranR3
      axios.get("http://localhost:8081/evaluatetaskarrange/searchmorethanone/"+searchUrl).then(function (res){
        _this.tableData=res.data
      })
      this.value=''
      this.search2=''
    },
    Export(){
      let tables = document.getElementById("out-table1");
      console.log(tables)
      let table_book = this.$XLSX.utils.table_to_book(tables);
      var table_write = this.$XLSX.write(table_book, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        this.$FileSaver.saveAs(
            new Blob([table_write], { type: "application/octet-stream" }),
            "EvaluateTaskArrange.xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, table_write);
      }
      return table_write;
    },
    TAAdd(){
      this.dialogFormVisible = true;
      this.modeName='添加评价安排'
      this.ruleForm={}
    },
    edit(row){
      this.dialogFormVisible = true
      this.modeName='更新评价安排'

      this.ruleForm=row
      this.allid=row.id
    },
    del(row){
      const _this=this
      const d=confirm("确定删除吗？");
      if (d){
        axios.delete('http://localhost:8081/evaluatetaskarrange/delete/'+row.id).then(()=>{
          axios.get("http://localhost:8081/evaluatetask/search/1/"+row.evaluatetaskid).then((res)=>{
            console.log(res.data[0])
            res.data[0].selectedschoolnumber=res.data[0].selectedschoolnumber-1
            axios.put("http://localhost:8081/evaluatetask/update",res.data[0]).then((res)=>{
            })
          })
          alert("删除成功")
          // location.reload();
          if((this.total-1)% 15===0){
            this.page(this.returnPage-1)
          }
          else {
            this.page(this.returnPage)
          }
        })
      }
    },
    detail(row) {
      axios.get("http://localhost:8081/evaluatetask/search/1/"+row.evaluatetaskid).then((res)=>{
        res.data.evaluatetaskopentime=this.$moment(res.data.evaluatetaskopentime).format('YYYY-MM-DD HH:mm:ss')
        res.data.evaluatetaskendtime=this.$moment(res.data.evaluatetaskendtime).format('YYYY-MM-DD HH:mm:ss')
        let time=new Date().getTime()
        let ot=new Date(res.data.evaluatetaskopentime).getTime()
        let et=new Date(res.data.evaluatetaskendtime).getTime()
        if  (time>=et){
          //已结束
          res.data.evaluateattitude='已过期'
        }
        else if (time<et && time >=ot){
          //进行中
          res.data.evaluateattitude='进行中'
        }
        else {
          //未开始
          res.data.evaluateattitude='未开始'
        }
        this.tableData2=res.data
      })
    },
    Evaluate(row){
      //根据学校名和任务号 检索出此任务评估填写信息

    },

  },

  data(){
    return {
      search2:'',
      radio1:'1',
      radio2:'2',
      radio3:'2',
      dialogTableVisible: false,
      dialogFormVisible: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      formLabelWidth: '120px',
      ruleForm: {
        // id:'',
        evaluatetaskid: '',
        schoolname: '',
        evaluatetaskname:'',
      },
      rules: {
        evaluatetaskid: [
          { required: true, message: '请填写评估任务号', trigger: 'blur' }
        ],
        schoolname: [
          { required: true, message: '请填写学校名称', trigger: 'blur' }
        ],
      },
      search:'',
      allid:'',
      isShow:true,
      mode:'',
      modeName:'',
      options: [],
      value: '',
      desc:'',
      total:null,
      returnPage:'',
      tableData: null,
      tableData1: null,
      tableData2: null,
      tableData3: null,
      dataList: [],
      fileList: [],
      query: {"page":0, "size":20, count:0},
      column: [
        {label: "序号", prop: "id", type: "string"},
        {label: "任务号", prop: "evaluatetaskid", type: "string"},
        {label: "学校名称", prop: "schoolname", type: "string"},

      ],
      editForm: {},
      editVisible: false,
      currentIndex: null,

    }
  },
  created() {
    const _this=this
    const a=localStorage.getItem("access-admin")
    if(a){
      axios.get('http://localhost:8081/evaluatetaskarrange/page?current=1&size=15').then(function (res){
        // console.log(res.data.current)
        _this.returnPage=res.data.current;
        _this.tableData=res.data.evaluatetaskarrangeList;
        _this.total=res.data.total;
      })
      axios.get('http://localhost:8081/evaluatetaskarrange/findAll').then(function (res){
        // console.log(res.data)
        // _this.tableData=res.data
        _this.tableData1=res.data
      })
      axios.get('http://localhost:8081/evaluatetask/findAll').then((res)=>{
        console.log('rsaes',res.data)
        for(let i=0;i<res.data.length;i++){
          this.options.push({value:i+1,label:res.data[i].evaluatetaskname})
        }
      })
    }
    else{
      this.$alert('未登录','提示',{
        confirmButtonText:'确定'
      }).then((res)=>{
        this.$router.replace({path:'/login'})
      })
    }

  }
}
</script>
